/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once

#include "GUIComponent.h"
#include "Hogshead.Input.h"

namespace Hogshead
{
	namespace DX11Rendering
	{
		class Texture;

		enum MouseLocationState
		{
			NOT_OVER = 1,
			OVER = 2
		};

		enum MouseDownState
		{
			UP = 4,
			DOWN = 8,
		};

		class GUIButtonReleasedMessage;

		/**
		* This class is a component that is used to render a button on the screen. This button has three 
		* states: default, rollover, and press. It inherits from GUIComponent which has the reference to the
		* material and constant buffer group.
		*
		* @see IGUIObject
		* @see GUIComponent
		* @see IComponent
		* @see Texture
		*
		* @author Ben Dapkiewicz
		*/
		class GUIButton : public GUIComponent, public IMessageSender
		{
			GUIComponentH(Hogshead::DX11Rendering::GUIButton, GUIButton)

		public:
			/**
			* Default Constructor; Sets the textures to NULL.
			*/
			GUIButton(void);

			/**
			* Destructor; Does nothing.
			*/
			~GUIButton(void);

			/**
			* initialize method; Used at initialization time to call initialize on the state textures.
			*/
			void initialize();

			/**
			* readXML method; Parses through XML data to set up properties for this component.
			*
			* @param in_xml The XML data to parse.
			*/
			IComponent* readXML(const String& in_xml);

			/**
			* update method; Function that is called every frame on all components.
			*
			* @param in_gt The game time.
			*/
			void update(const GameTimer& in_gt);



		private:
			GUIButtonReleasedMessage* _released_message;
			int state_flags;
			int previous_state_flags;

			bool _fullscreen;
			bool _center;
			float _percent_from_bottom;

			bool checkMouseOver(const Vector2& mouse_position);

			//textures for the three button states
			Texture* _up_state_texture;
			Texture* _over_state_texture;
			Texture* _down_state_texture;

			DirectInputDirector* _did;

			static void handle_mouse_down(IMessageReceiver* self, IMessage* message);
			static void handle_mouse_up(IMessageReceiver* self, IMessage* message);
			static void handle_mouse_move(IMessageReceiver* self, IMessage* message);
		};
	}
}